using System;
using System.Data.Entity.ModelConfiguration;
using System.Data.Common;
using System.Data.Entity;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using DataAccess.Entities;

namespace DataAccess.Mapping
{
	public class UserTrackMap : EntityTypeConfiguration<UserTrack>
	{
		public UserTrackMap()
		{
			// Primary Key
			this.HasKey(t => t.Id);

			// Properties
			this.Property(t => t.Ip)
				.HasMaxLength(50);
				
			// Table & Column Mappings
			this.ToTable("UserTrack");
			this.Property(t => t.Id).HasColumnName("Id");
			this.Property(t => t.OrgId).HasColumnName("OrgId");
			this.Property(t => t.UserId).HasColumnName("UserId");
			this.Property(t => t.Ip).HasColumnName("Ip");
			this.Property(t => t.CreateDate).HasColumnName("CreateDate");

			// Relationships
			this.HasOptional(t => t.Organization)
				.WithMany(t => t.UserTracks)
				.HasForeignKey(d => d.OrgId);
				
			this.HasOptional(t => t.User)
				.WithMany(t => t.UserTracks)
				.HasForeignKey(d => d.UserId);
				
		}
	}
}

